<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>柠檬水找零钱</title>
</head>
<body>
  <script>
    var nums = [5, 5, 10, 10, 20]
    function fn(bills) {
      let a = 0, b = 0;
      for(let i in bills) {
        if(bills[i] === 5) {
          a++
        } else if(bills[i] === 10) {
          if(a == 0) return false;
          a--;
          b++;
        } else if(a > 0 && b > 0) {
          a--;
          b--;
        } else if(a >= 3) {
          a -= 3
        } else {
          return false
        }
      }
      return true
    }
    console.log(fn(nums))
  </script>
</body>
</html>